//--------------------Sonic CD HUD Script---------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
// Not all of these are used here in the HUD script, some are just used as a way for other objects to globally transmit values
private alias Object.Value0 : Object.Timer     // Initially set via a loop in the UFO script
private alias Object.Value1 : Object.ShadowFreddyTimer     // Initially set via a loop in the UFO script
private alias Object.Value3 : Object.ShadowFreddyRandom    // Initially set via a loop in the UFO script
private alias Object.Value4 : Object.ShadowFreddyAI    // Initially set via a loop in the UFO script
private alias Object.Value5 : Object.ScareTimer    // Initially set via a loop in the UFO script

private alias Object.Value6 : Object.ShadowFreddyRise    // Initially set via a loop in the UFO script
private alias Object.Value7 : Object.MoveTime    // Initially set via a loop in the UFO script
private alias Object.Value8 : Object.RandomLocation1    // Initially set via a loop in the UFO script

private alias Object.Value9 : Object.Cooldown    // Initially set via a loop in the UFO script
private alias Object.Value10 : Object.HeadShake    // Initially set via a loop in the UFO script
private alias Object.Value11 : Object.Tweak    // Initially set via a loop in the UFO script

private alias Object.Value12 : Object.ShadowFreddyActivate    // Initially set via a loop in the UFO script

private alias Object.Value13 : Object.FlashTimer    // Initially set via a loop in the UFO script


private alias Object[6].Value1 : Object.CameraState

// Priority
private alias 1 : PRIORITY_ACTIVE

private alias 0 : CAM_SHOWSTAGE_0
private alias 1 : CAM_DININGHALL_1
private alias 2 : CAM_BACKSTAGE_2
private alias 3 : CAM_PIRATESCOVE_3
private alias 4 : CAM_WESTHALL_4
private alias 5 : CAM_CLOSET_5
private alias 6 : CAM_WHALLCORNER_6
private alias 7 : CAM_EASTHALL_7
private alias 8 : CAM_EHALLCORNER_8
private alias 9 : CAM_KITCHEN_9
private alias 10 : CAM_BATHROOMS_10

private alias 15 : OFFICE_ATDOOR
private alias 16 : OFFICE_JUMPSCARES

private alias object.state : ShadowFreddy.State

private alias 0  : CAMERA_WAITACTIVATE
private alias 1  : CAMERA_FLIPUP
private alias 2  : CAMERA_MAIN
private alias 10  : CAMERA_EXIT

event ObjectMain
//-1 is basically the ai level 0 ig

if Object[5].Type == TypeName[Blank Object]

	switch ShadowFreddy.state
	case 15
		PlaySfx(SfxName[Scream2], 0)			
		object.state = 17
	break
	case 17
		if Object.ShadowFreddyRise > -100
			Object.ShadowFreddyRise -= 16
		else
			Object.ShadowFreddyRise = -100
		end if

		if Object.ShadowFreddyRise == -100
			Object.FlashTimer++
			if Object.FlashTimer == 100
				object.alpha = 255
				object.state++
				Object.FlashTimer = 0
			end if
		end if	
	break	
	case 18
		if object.alpha > 0
			object.alpha -= 4
		end if	
	break
	default
		if Object.ShadowFreddyActivate == 0
			if Object.Cooldown > 0
				Object.Cooldown--
			end if

			if Object.Cooldown == 0
				Object.ShadowFreddyTimer++
				if Object.ShadowFreddyTimer == 100
					Rand(Object.ShadowFreddyRandom, 21)
					Object.ShadowFreddyTimer = 0
				end if	
				if object[6].state == CAMERA_FLIPUP
					if Object.ShadowFreddyAI > Object.ShadowFreddyRandom 
						object.alpha = 255
						Object.ShadowFreddyTimer = 0
						Object.ShadowFreddyActivate = 1
					end if
				end if
			end if
		else
				ShadowFreddy.state = Object.CameraState	

				Object.ShadowFreddyTimer++
				Object.MoveTime = 100
				rand(temp3, 100)
				Object.MoveTime += temp3
				//RNG to try and move
				if Object.ShadowFreddyTimer >= Object.MoveTime 
					Rand(Object.RandomLocation1, 10)
					//actually moving
					if Object.ShadowFreddyAI >= Object.ShadowFreddyRandom 
						//these align with the cameras he goes to
						//state 10 is cam 10
						//15+ is at the office watch out

						if Object[6].value1 == ShadowFreddy.state
							object[6].alpha = 355
						end if				

						//you die :)
						ForcePull = 1 
						ShadowFreddy.state = 15
						
						if Object[6].value1 == ShadowFreddy.state
							object[6].alpha = 355
						end if	

					
					end if
					Object.ShadowFreddyTimer = 0	
				end if


				if object[6].state == CAMERA_EXIT
					object.Cooldown = 500
					Object.ShadowFreddyActivate = 0
					Object.ShadowFreddyTimer = 0
				end if

		end if	
	break
	end switch
end if	
end event

event ObjectDraw

//	DrawNumbers(0, 32, 96, ShadowFreddy.state, 3, 8, 0)

//	DrawNumbers(0, 64, 96, Object.ShadowFreddyActivate, 3, 8, 0)

	rand(Object.HeadShake, 6)

//	DrawNumbers(0, 96, 96, Object.HeadShake, 3, 8, 0)

	switch object.state
	case 17
		object.drawOrder = 5
		temp1 = Screen.xsize
		temp1 /= 2
		temp1 -= 140

		temp2 = temp1
		temp2 += Object.HeadShake

		DrawSpriteScreenFX(10, FX_SCALE, temp2, Object.ShadowFreddyRise)	//body
		DrawSpriteScreenFX(11, FX_SCALE, temp2, Object.ShadowFreddyRise)	//head
	break
	case 18

		DrawRect(0, 0, screen.xsize, screen.ysize, 0, 0, 0, object.alpha)// 1
	break
	end switch

	

end event


event ObjectStartup
	
	LoadSpriteSheet("FNAF/Jumpscares.gif")
	
	// Place the HUD object into reserved object slot 4 and initialise its values
	Object[28].Type = TypeName[ShadowFreddy]
	
	// The object should always be run, regardless if it's within camera bounds or not
	Object[28].Priority = PRIORITY_ACTIVE
	
	// Make the HUD draw ontop of all other sprites, too
	Object[28].DrawOrder = 5

	Object[28].Cooldown = 500

	// 0-9 - Numbers 0-9
	SpriteFrame(0, 0, 8, 13, 558, 1)
	SpriteFrame(0, 0, 8, 13, 567, 1)
	SpriteFrame(0, 0, 8, 13, 576, 1)
	SpriteFrame(0, 0, 8, 13, 585, 1)
	SpriteFrame(0, 0, 8, 13, 594, 1)
	SpriteFrame(0, 0, 8, 13, 558, 15)
	SpriteFrame(0, 0, 8, 13, 567, 15)
	SpriteFrame(0, 0, 8, 13, 576, 15)
	SpriteFrame(0, 0, 8, 13, 585, 15)
	SpriteFrame(0, 0, 8, 13, 594, 15)

	SpriteFrame(-38, 280, 352, 91, 300, 1024)
	SpriteFrame(46, 100, 188, 221, 300, 1116)	//11


end event


// ========================
// Editor events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("3D_Test/Objects.gif")
	SpriteFrame(0, 0, 24, 16, 206, 58)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
